package wk.coral.util.applicationContext;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * description:
 * date 2021-01-16 14:48
 *
 * @author Administrator
 * @version 1.0
 */
public final class ApplicationContextUtil {

    private ApplicationContextUtil(){}

    private static ApplicationContext context;

    /**
     * set context
     * @param context
     */
    public static void setContext(ApplicationContext applicationContext){
        context = applicationContext;
    }

    /**
     * get bean by beanName
     * @param beanName
     * @return
     */
    public static Object getBean(String beanName){
        return context.getBean(beanName);
    }

    /**
     * get bean by class
     * @param clazz
     * @return
     */
    public static <T> T getBean(Class<T> clazz){
        return context.getBean(clazz);
    }
}
